package com.ict.web.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.ProfessionalQualification;
import com.ict.web.domain.TechnicalTitle;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;

@Data
public class InsertTechnicalTitleDto {

  @ApiModelProperty(value = "职称名称")
  private String jobTitle;

  @ApiModelProperty(value = "通过时间")
  @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  private Date passingTime;

  @ApiModelProperty(value = "附件")
  private YzqFileDTO technicalFile;

  @ApiModelProperty(value = "截止时间")
  @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
  @DateTimeFormat(pattern = "yyyy-MM-dd")
  private Date deadline;


  public static TechnicalTitle of(InsertTechnicalTitleDto AddDto){
    TechnicalTitle bean = new TechnicalTitle();
    BeanUtils.copyProperties(AddDto,bean);
    //设置ID
    bean.setTechnicalId(IdUtils.snowId());
    //设置创建时间
    bean.setCreateTime(LocalDateTime.now());
    //设置创建时间
    bean.setUpdateTime(LocalDateTime.now());
    //设置物理删除标记
    bean.setDelFlag(TechnicalTitle.DELETE_STATUS_NORMAL);

    return bean;
  }

  /**
   * 将 InsertTechnicalTitleDto中需传文件对象 转化为 file
   *
   * @param dto 接收dto
   * @return HotelInfo
   */
  public static ArrayList<YzqFile> toFile(TechnicalTitle technicalTitle, InsertTechnicalTitleDto dto) {
    ArrayList<YzqFile> fileList = new ArrayList<>();
    if (dto.getTechnicalFile() != null) {
      YzqFileDTO Tf = dto.getTechnicalFile();
      YzqFile fileTf = new YzqFile();
      fileTf.setId(String.valueOf(IdUtils.snowId()));
      BeanUtils.copyProperties(Tf, fileTf);
      fileList.add(fileTf);
      technicalTitle.setTechnicalFile(fileTf.getId());
    }
    return fileList;
  }
}
